#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main()
{ 
  int pipefd[2] = {0};

  pipe(pipefd);

  pid_t id = fork();
  if(0 == id){
    //child,read 
    close(pipefd[1]);//close write 
    char buffer[64];
    while(1){
      ssize_t s = read(pipefd[0], buffer, sizeof(buffer)-1);
      if(s > 0)
      {
        buffer[s] = '\0';
        printf("child get message: %s\n", buffer);
      }
    }
  }
  else{
    //father,write  
    close(pipefd[0]);//close read 
    const char * msg = "I am father ... \n";
    while(1){
      write(pipefd[1], msg, strlen(msg));//write some
      sleep(1);
      }
    }
  
  return 0;
}
